package com.example.demo.service.impl;

import com.example.demo.service.MyProcessModelService;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.ui.modeler.domain.Model;
import org.flowable.ui.modeler.serviceapi.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: njz
 * @Description:
 * @Date: create in 2022/2/11 14:49
 */
@Service
public class MyProcessModelServiceImpl implements MyProcessModelService {

    @Autowired
    private ModelService modelService;

    @Autowired
    private RepositoryService repositoryService;

    @Override
    public String deployProcessModel(String modelId) {
        Model model = modelService.getModel(modelId);
        BpmnModel bpmnModel = modelService.getBpmnModel(model);
        Deployment deployment = repositoryService.createDeployment()
                .name(model.getName())
                .addBpmnModel(model.getKey()+".bpmn",bpmnModel)
                .deploy();
        return deployment.getId();
    }

}
